<template>
  <el-form style="width: 60%" :model="ruleForm" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item  prop="case_id"
                   label="测试用例标识">
      <el-input v-model="ruleForm.case_id"></el-input>
    </el-form-item>
    <el-form-item  prop="test_user"
                   label="测试人员">
      <el-input v-model="ruleForm.test_user"></el-input>
    </el-form-item>

    <el-form-item prop="datetime"
                  label="测试时间">
      <el-input v-model="ruleForm.datetime"></el-input>
    </el-form-item>
    <el-form-item prop="case_edition"
                  label="测试版本">
      <el-input v-model="ruleForm.case_edition"></el-input>
    </el-form-item>
    <el-form-item   prop="case_result"
                    label="实际测试结果">
      <el-input v-model="ruleForm.case_result"></el-input>
    </el-form-item>
    <el-form-item   prop="result"
                    label="执行结果">
      <el-input v-model="ruleForm.case_result"></el-input>
    </el-form-item>
    <el-form-item   prop="problem_id"
                    label="问题标识">
      <el-input v-model="ruleForm.problem_id"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="密码" @click="submitForm('ruleForm')">提交</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
      <el-button type="danger" round @click="deleteForm()">删除</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import axios from 'axios'

export default {
  data() {
    return {
      ruleForm: {
        case_id: '',
        test_user: '',
        datetime: '',
        case_edition: '',
        case_result: '',
        result: '',
        problem_id: ''
      }
    };
  },
  methods: {
    submitForm (formName) {
      const _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios.post('http://localhost:8088/case_test/save', this.ruleForm).then(function (resp) {
            if (resp.data === 'success') {
              _this.$alert('《' + _this.ruleForm.case_id + '》更新成功！', '消息', {
                confirmButtonText: '确定',
                callback: action => {
                  _this.$router.push('/Main')
                }
              })
            }
          })
        } else {
          return false;
        }
      });
    },
    resetForm (formName) {
      this.$refs[formName].resetFields();
    },
    deleteForm () {
      const _this = this
      axios.delete('http://localhost:8088/case_test/deleteById/' + this.$route.query.id).then(function (resp) {
        _this.$alert({
          confirmButtonText: '确定',
          callback: action => {
            window.location.reload()
          }
        })
      })
    }
  },
  created() {
    const _this = this
    axios.get('http://localhost:8088/case_test/findById/' + this.$route.query.id).then(function(resp) {
      _this.ruleForm = resp.data
    })
  }
}
</script>

<style scoped>

</style>
